package com.yulebaby.callsenter.ui.activity;

import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemChildClickListener;
import com.fourmob.datetimepicker.date.DatePickerDialog;
import com.yulebaby.callsenter.R;
import com.yulebaby.callsenter.adapter.ActualTranNotesTodayAdapter;
import com.yulebaby.callsenter.bean.PreTranRecordTodayBean;
import com.yulebaby.callsenter.global.Constant;
import com.yulebaby.callsenter.http.callback.HttpCallback;
import com.yulebaby.callsenter.task.RequestTranProgressTask;
import com.yulebaby.callsenter.ui.base.BaseActivity;
import com.yulebaby.callsenter.ui.view.YuLeBaByLinearLayoutManager;
import com.yulebaby.callsenter.utils.DateUtil;
import com.yulebaby.callsenter.utils.ToastUtil;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 根据实际转换步骤查看跟踪进展
 */
public class ActualTransNotesActivity extends BaseActivity {

    @BindView(R.id.iv_back)
    ImageView mIvBack;
    @BindView(R.id.rv_notes)
    RecyclerView mRvNotes;

    private List<PreTranRecordTodayBean> tranList;
    private ActualTranNotesTodayAdapter mTodayAdapter;

    @Override
    protected int initLayoutId() {
        return R.layout.activity_actual_trans_notes;
    }

    @Override
    protected void initView() {
    }

    @Override
    protected void initData() {
        tranList = new ArrayList<>();
        mTodayAdapter = new ActualTranNotesTodayAdapter(tranList);
        mRvNotes.setHasFixedSize(true);
        mRvNotes.setLayoutManager(new YuLeBaByLinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
        mRvNotes.addOnItemTouchListener(new OnItemChildClickListener() {
            @Override
            public void onSimpleItemChildClick(BaseQuickAdapter baseQuickAdapter, View view, int position) {
                PreTranRecordTodayBean bean = (PreTranRecordTodayBean) baseQuickAdapter.getItem(position);
                switch (view.getId()) {
                    case R.id.rl_trackprogress:
                        if (bean.getTrack_pro() > 3) {
                            Intent intent = new Intent(ActualTransNotesActivity.this, LookOverTrackProgressActivity.class);
                            intent.putExtra(Constant.PRE_VISIT_TIMES, bean.getVisit_times());
                            intent.putExtra(Constant.CUSTOMER_ID, bean.getCustomer_id());
                            startActivity(intent);
                        }
                        break;
                }
            }
        });
        mRvNotes.setAdapter(mTodayAdapter);
        requestData(getIntent().getIntExtra(Constant.TRA_PRO, -1)); //获取跟踪步骤
    }

    /**
     * 请求跟踪数据
     *
     * @param pro 跟踪步骤
     */
    private void requestData(int pro) {
        if (pro != -1) {
            RequestTranProgressTask.doRequestFindPreTrackToday(this, pro, new HttpCallback<List<PreTranRecordTodayBean>>() {
                @Override
                public void onSuccess(List<PreTranRecordTodayBean> result) {
                    processResult(result);
                }
            });
        } else {
            ToastUtil.showToast("跟踪步数有误");
        }
    }

    /**
     * 结果处理
     *
     * @param result
     */
    private void processResult(List<PreTranRecordTodayBean> result) {
        if (result != null && result.size() > 0) {
            tranList.clear();
            tranList.addAll(result);
            mTodayAdapter.notifyDataSetChanged();
        }

    }

    @OnClick(R.id.iv_back)
    public void onClick() {
        finish();
    }

}
